package com.xqc.rabbit.topic;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.xqc.rabbit.ConnectionUtils;

/**
* @author 作者 Gavin.Dai/SNSSZ00036
* @dateTime 创建时间：2020年8月11日 下午1:09:15
* @version V1.0.0
* 类说明
*/
public class TopicProduct {
	
	public static final String EXCHANGE_NAME = "topic_exchange";

	public static void main(String[] args) throws IOException, TimeoutException {
		Connection conn = ConnectionUtils.getConn();
		//声明信道
		Channel channel = conn.createChannel();
		// 声明exchange，指定类型为direct
		channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.TOPIC,true);
		//指定routingKey，个人理解实际上就是过滤的作用，消费端与此匹配的则才可以接受到消息
		String routingKey = "success.update.customer";
		for (int i = 0; i <10; i++) {
			//消息内容
			String message = "订阅主题模式"+i;
			//发布消息
			channel.basicPublish(EXCHANGE_NAME, routingKey, null, message.getBytes());
		}
		//关闭
		channel.close();
		conn.close();
	}
}
